<include file="Public:head"/>
        <div class="col-xs-12">
            <div class="tabbable">
                <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab">
                    <li class="active"> <a href="#home" data-toggle="tab">权限列表</a></li>
                    <li> <a href="javascript:;" onclick="add()">添加权限</a></li>
                </ul>
                <div class="tab-content">
                    <table class="layui-table">
                        <tr>
                            <th>权限名</th>
                            <th>权限</th>
                            <th>操作</th>
                        </tr>
                        <foreach name="data" item="v">
                            <tr>
                                <td>{$v['_name']}</td>
                                <td>{$v['name']}</td>
                                <td>
                                    <a href="javascript:;" ruleId="{$v['id']}" onclick="add_child(this)">添加子权限</a> | <a href="javascript:;" ruleId="{$v['id']}" ruleName="{$v['name']}" ruleTitle="{$v['title']}" onclick="edit(this)">修改</a> | <a href="javascript:;" onclick="del('{:U('Admin/Rule/delete',array('id'=>$v['id']))}', {$v['id']})"">删除</a>
                                </td>
                            </tr>
                        </foreach>
                    </table>
                </div>
            </div>
        </div>
        <div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header"> 
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                        <h4 class="modal-title" id="myModalLabel"> 添加权限</h4>
                    </div>
                    <div class="modal-body">
                        <form id="bjy-form" class="layui-form" action="{:U('Admin/Rule/add')}" method="post"> 
                            <input type="hidden" name="pid" value="0">
                            <div class="layui-form-item">
                                <label class="layui-form-label">权限名：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" placeholder="权限名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">权限：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" placeholder="Admin/Rule/index" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">输入模块/控制器/方法 例如 Admin/Rule/index</div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                  <button class="layui-btn" lay-submit lay-filter="addRule">添加</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header"> 
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                        <h4 class="modal-title" id="myModalLabel"> 修改权限</h4>
                    </div>
                    <div class="modal-body">
                        <form id="bjy-form" class="form-inline" action="{:U('Admin/Rule/edit')}" method="post">
                            <input type="hidden" name="id">
                            <div class="layui-form-item">
                                <label class="layui-form-label">权限名：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" placeholder="权限名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">权限：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" placeholder="Admin/Rule/index" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">输入模块/控制器/方法 例如 Admin/Rule/index</div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                  <button class="layui-btn" lay-submit lay-filter="editRule">修改</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
<style type="text/css">
    .tab-content .layui-table td{
        text-align: left;
    }
</style>
<script>
    $(document).ready(function(){
        layui.use('form', function(){
            var form = layui.form;
            // 验证
            form.verify({
                // money:[/^(([1-9]\d*)|\d)(\.\d{1,2})?$/,"请输入正确的价格！"],
            });      
            //监听提交修改
            form.on('submit(editRule)', function(data){
                $(data.form).ajaxSubmit({
                    url:"{:U('Admin/Rule/edit')}",
                    type: 'post',
                    beforeSubmit:function(ormData,jqForm,options){
                        //加载层-风格4
                        layer.msg('加载中...', {
                          icon: 16,
                          shade: 0.2,
                          time:0,
                        });
                    },
                    success:function(responseText,statusText){
                        layer.closeAll();
                        if(responseText.status == 1){
                            layer.msg(responseText.info, {icon: 6,shade: 0.2,time:1000},function(){
                                location.href = responseText.url;
                            });
                        }else{
                            layer.msg(responseText.info, {icon: 5,shade: 0.2,time:1000});
                        }
                    },
                });
                //layer.msg(JSON.stringify(data.field));
                return false;
            });
            //监听提交添加
            form.on('submit(addRule)', function(data){
                $(data.form).ajaxSubmit({
                    url:"{:U('Admin/Rule/add')}",
                    type: 'post',
                    beforeSubmit:function(ormData,jqForm,options){
                        //加载层-风格4
                        layer.msg('加载中...', {
                          icon: 16,
                          shade: 0.2,
                          time:0,
                        });
                    },
                    success:function(responseText,statusText){
                        layer.closeAll();
                        if(responseText.status == 1){
                            layer.msg(responseText.info, {icon: 6,shade: 0.2,time:1000},function(){
                                location.href = responseText.url;
                            });
                        }else{
                            layer.msg(responseText.info, {icon: 5,shade: 0.2,time:1000});
                        }
                    },
                });
                //layer.msg(JSON.stringify(data.field));
                return false;
            });
        });
    });
    // 添加菜单
    function add(){
        $("input[name='title'],input[name='name']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj){
        var ruleId=$(obj).attr('ruleId');
        $("input[name='pid']").val(ruleId);
        $("input[name='title']").val('');
        $("input[name='name']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var ruleId=$(obj).attr('ruleId');
        var ruletitle=$(obj).attr('ruletitle');
        var ruleName=$(obj).attr('ruleName');
        $("input[name='id']").val(ruleId);
        $("input[name='title']").val(ruletitle);
        $("input[name='name']").val(ruleName);
        $('#bjy-edit').modal('show');
    }
</script>
<include file="Public:foot"/>